package com.youlu.campus.monitor.controller;

import com.youlu.campus.common.base.QResult;
import com.youlu.campus.monitor.entity.WechatMonitor;
import com.youlu.campus.monitor.entity.WechatMonitorPageQuery;
import com.youlu.campus.monitor.service.WechatMonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信监控接口层
 *
 * @author su
 * @date 2025/09/02
 */
@RestController
@RequestMapping("/wechat/monitor")
public class WechatMonitorController {

    @Autowired
    private WechatMonitorService wechatMonitorService;

    /**
     * 新增微信监控记录
     * 请求方式：POST
     * 请求体：JSON格式的WechatMonitor实体（无需传id，MongoDB自动生成）
     */
    @PostMapping("/save")
    public QResult<WechatMonitor> saveWechatMonitor(@RequestBody WechatMonitor wechatMonitor) {
        wechatMonitor = wechatMonitorService.saveWechatMonitor(wechatMonitor);
        return QResult.success(wechatMonitor);

    }

    /**
     * 根据ID删除微信监控记录
     * 请求方式：DELETE
     * 路径参数：id（MongoDB的_id）
     */
    @PostMapping("/delete")
    public QResult<Boolean> deleteWechatMonitorById(@RequestBody WechatMonitor wechatMonitor) {
        Boolean b = wechatMonitorService.deleteWechatMonitorById(wechatMonitor.getId());
        return QResult.success(b);
    }


    /**
     * 根据ID查询微信监控记录详情
     * 请求方式：GET
     * 路径参数：id（MongoDB的_id）
     */
    @GetMapping("/info")
    public QResult<WechatMonitor> getWechatMonitorById(@RequestParam String id) {
        WechatMonitor wechatMonitor = wechatMonitorService.getWechatMonitorById(id);
        return QResult.success(wechatMonitor);
    }

    /**
     * 分页查询微信监控记录列表
     *
     * @param query
     * @return
     */
    @PostMapping("/find-page")
    public QResult<Page<WechatMonitor>> findByPage(@RequestBody WechatMonitorPageQuery query) {
        Page<WechatMonitor> page = wechatMonitorService.findByPage(query);
        return QResult.success(page);
    }
}
    